/* 
 * Partition data structure.
 * Copyright (C) 2006 Bob Zimmermann <rpz@cse.wustl.edu>
 *
 *  This file is a part of BAT.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * partition.h
 *
 * Partition data structure.
 *
 * $Id: partition.h 1409 2006-09-20 20:30:33Z rpz $
 *
 */

#include "darray.h"

#ifndef PARTITION_H
#  define PARTITION_H

typedef struct _partition_node_t partition_node_t;
typedef struct _partition_t partition_t;
typedef void (*partition_delete_op) (void *, int);

typedef da_pos_t part_pos_t;

typedef struct _partition_ops_t
{
  partition_delete_op delete;
} partition_ops_t;


struct _partition_node_t
{
  part_pos_t rank;
  da_pos_t parent;
};

struct _partition_t
{
  darray_t *nodes;
  darray_t *data;
};

partition_ops_t *partition_ops_new (partition_delete_op delete);
partition_ops_t *partition_ops_copy (const partition_ops_t * po);
void partition_ops_delete (partition_ops_t * po, int);

partition_t *partition_new (int init_size, partition_ops_t * ops);
partition_t *partition_new_from_darray (darray_t *);
void partition_delete (partition_t * p, int);

void partition_clear(partition_t *, int);

part_pos_t partition_size (partition_t *);
void partition_add (partition_t *, void *);
void partition_set (partition_t *, part_pos_t, void *);
void *partition_get (partition_t *, part_pos_t);
void **partition_get_array (partition_t *);
void partition_link (partition_t *, part_pos_t, part_pos_t);
part_pos_t partition_find (partition_t *, part_pos_t);

#endif /* PARTITION_H */
